from pymysql import Connection

# 构建MySQL数据库的连接
connect = Connection(
    host='172.16.100.10',
    port=3306,
    user='root',
    password='Tcdn@2007.'
)

# 执行非查询性质的SQL语句
# 获取游标对象
# cursor = connect.cursor()
# connect.select_db("test")       # 先选择数据库
# 使用游标对象，执行sql语句
# cursor.execute("create table test_pymysql2(id int)")

# 执行查询性质的SQL语句：
cursor = connect.cursor()
connect.select_db("world")
cursor.execute("select * from student")

# 获取查询结果
results = cursor.fetchall()
for r in results:
    print(r)

# 关闭数据库的链接
connect.close()